from pymongo import MongoClient  

# 连接到MongoDB（确保MongoDB服务已在本地运行）  
client = MongoClient("mongodb://192.168.168.110:27017/")  

# 选择数据库  
db = client['data']  

# 用户名和卡牌列表  
username = "whfm"  
cards = ['Q', 'K', 'K', '大王', 'K']  

# 为每张牌创建一个文档并插入  
for card in cards:  
    usercard_data = {  
        "username": username,  
        "card": card  # 每次仅使用一张牌  
    }  
    # 插入文档到 usercard 集合  
    db.usercard.insert_one(usercard_data)  

# 验证插入的数据  
print(f"Usercards for {username}:")  
for entry in db.usercard.find({"username": username}):  
    print(entry)  

# 关闭MongoDB连接  
client.close()